/*
 * Jenny Ruppen 09-730-391
 * Sebastien Goldberg 08-914-855
 * Henry Raymond 08-928-061
 * Stefan Mussato 09-752-270
 */
 
package ch.uzh.ifi.sopra.gruppe9.game;

import com.jme3.scene.Node;


/**
 * Draws a window in the GUI.
 */
public class GuiWindow extends Node {
	
	
	/**
	 * Offset of the coordinate system of this window.
	 */
	private GUI.Offset offset;
	
	
	/**
	 * Position of the window in the x axis. (Assuming the jME3 window has a width of 1024 pixel.)
	 */
	private int positionX;
	
	
	/**
	 * Position of the window in the y axis. (Assuming the jME3 window has a height of 768 pixel.)
	 */
	private int positionY;
	
	
	/**
	 * Width of the window. (Assuming the jME3 window has a width of 1024 pixel.)
	 */
	private int width;
	
	
	/**
	 * Height of the window. (Assuming the jME3 window has a height of 768 pixel.)
	 */
	private int height;
	
	
	/**
	 * Z-Index of the element. An element with a higher index will cover an element with a lower one.
	 */
	private int zIndex;
	
	
	/**
	 * Constructor
	 */
	public GuiWindow(GUI.Offset offset, int positionX, int positionY, int width, int height, int zIndex) {
		this.offset = offset;
		this.positionX = positionX;
		this.positionY = positionY;
		this.width = width;
		this.height = height;
		this.zIndex = zIndex;
		
		GuiQuad cornerTopLeft = new GuiQuad();
		cornerTopLeft.setAbsolutePositionSize(-20, -20, 60, 60, 0);
		cornerTopLeft.setMaterial(MaterialManager.getWindow(), 0.0f, 0.0f, 0.375f, 0.375f);
		this.attachChild(cornerTopLeft.create());
		
		GuiQuad cornerTopRight = new GuiQuad();
		cornerTopRight.setAbsolutePositionSize(width - 40, -20, 60, 60, 0);
		cornerTopRight.setMaterial(MaterialManager.getWindow(), 0.625f, 0.0f, 0.375f, 0.375f);
		this.attachChild(cornerTopRight.create());
		
		GuiQuad cornerBottomLeft = new GuiQuad();
		cornerBottomLeft.setAbsolutePositionSize(-20, height - 40, 60, 60, 0);
		cornerBottomLeft.setMaterial(MaterialManager.getWindow(), 0.0f, 0.625f, 0.375f, 0.375f);
		this.attachChild(cornerBottomLeft.create());
		
		GuiQuad cornerBottomRight = new GuiQuad();
		cornerBottomRight.setAbsolutePositionSize(width - 40, height - 40, 60, 60, 0);
		cornerBottomRight.setMaterial(MaterialManager.getWindow(), 0.625f, 0.625f, 0.375f, 0.375f);
		this.attachChild(cornerBottomRight.create());
		
		GuiQuad lineTop = new GuiQuad();
		lineTop.setAbsolutePositionSize(40, -20, width - 80, 60, 0);
		lineTop.setMaterial(MaterialManager.getWindow(), 0.375f, 0.0f, 0.25f, 0.375f);
		this.attachChild(lineTop.create());
		
		GuiQuad lineButton = new GuiQuad();
		lineButton.setAbsolutePositionSize(40, height - 40, width - 80, 60, 0);
		lineButton.setMaterial(MaterialManager.getWindow(), 0.375f, 0.625f, 0.25f, 0.375f);
		this.attachChild(lineButton.create());
		
		GuiQuad lineLeft = new GuiQuad();
		lineLeft.setAbsolutePositionSize(-20, 40, 60, height - 80, 0);
		lineLeft.setMaterial(MaterialManager.getWindow(), 0.0f, 0.375f, 0.375f, 0.25f);
		this.attachChild(lineLeft.create());
		
		GuiQuad lineRight = new GuiQuad();
		lineRight.setAbsolutePositionSize(width - 40, 40, 60, height - 80, 0);
		lineRight.setMaterial(MaterialManager.getWindow(), 0.625f, 0.375f, 0.375f, 0.25f);
		this.attachChild(lineRight.create());
		
		//background texture scale
		float tS = 0.00260416f;
		
		GuiQuad backgroundTop = new GuiQuad();
		backgroundTop.setAbsolutePositionSize(10, 0, width - 20, 10, -0.5f);
		backgroundTop.setMaterial(MaterialManager.getMarble(), 10.0f * tS, 0.0f, (width - 20.0f) * tS, 10.0f * tS);
		this.attachChild(backgroundTop.create());
		
		GuiQuad backgroundMiddle = new GuiQuad();
		backgroundMiddle.setAbsolutePositionSize(0, 10, width, height - 20, -0.5f);
		backgroundMiddle.setMaterial(MaterialManager.getMarble(), 0.0f, 10.0f * tS, width * tS, (height - 20.0f) * tS);
		this.attachChild(backgroundMiddle.create());
		
		GuiQuad backgroundBottom = new GuiQuad();
		backgroundBottom.setAbsolutePositionSize(10, height - 10, width - 20, 10, -0.5f);
		backgroundBottom.setMaterial(MaterialManager.getMarble(), 10.0f * tS, (height - 10.0f) * tS, (width - 20.0f) * tS, 10.0f * tS);
		this.attachChild(backgroundBottom.create());
		
		this.setLocalTranslation(GUI.calculateX(offset, positionX), GUI.calculateY(offset, positionY), (float)zIndex);
	}


	public GUI.Offset getOffset() {
		return offset;
	}


	public int getPositionX() {
		return positionX;
	}


	public int getPositionY() {
		return positionY;
	}


	public int getWidth() {
		return width;
	}


	public int getHeight() {
		return height;
	}


	public int getZIndex() {
		return zIndex;
	}

}
